package com.dxf.utils;

import com.dxf.database.dbInfo.DataBase;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * 连接数据库工厂
 */
public class DriverManagerFactory {


    //获取连接
    public static Connection getConnection(DataBase dataBase) throws ClassNotFoundException, SQLException {
        // 获取数据库基本信息
        //注册驱动
        Class.forName(dataBase.getDriver());
        //获取连接
        Properties properties = new Properties();
        properties.put("user", dataBase.getUserName());
        properties.put("password", dataBase.getPassWord());
        /*properties.put("remarksReporting", "true");//获取数据库的备注信息
        properties.put("useInformationSchema", "true");*/

        properties.setProperty("remarks", "true"); //设置可以获取remarks信息
        properties.setProperty("useInformationSchema", "true");//设置可以获取tables remarks信息

        return DriverManager.getConnection(dataBase.getUrl(), properties);
    }



}
